package com.property.web.controller.management;

import java.util.List;

import com.property.management.domain.CourtInfo;
import com.property.management.service.ICourtInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.property.common.annotation.Log;
import com.property.common.enums.BusinessType;
import com.property.management.domain.CarportInfo;
import com.property.management.service.ICarportInfoService;
import com.property.common.core.controller.BaseController;
import com.property.common.core.domain.AjaxResult;
import com.property.common.utils.poi.ExcelUtil;
import com.property.common.core.page.TableDataInfo;

/**
 * 车位信息Controller
 * 
 * @author property
 * @date 2021-05-06
 */
@Controller
@RequestMapping("/property/carport")
public class CarportInfoController extends BaseController
{
    private String prefix = "property/carport";

    @Autowired
    private ICarportInfoService carportInfoService;
    @Autowired
    private ICourtInfoService courtInfoService;

    @RequiresPermissions("property:carport:view")
    @GetMapping()
    public String carport()
    {
        return prefix + "/carport";
    }

    /**
     * 查询车位信息列表
     */
    @RequiresPermissions("property:carport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarportInfo carportInfo)
    {
        startPage();
        List<CarportInfo> list = carportInfoService.selectCarportInfoList(carportInfo);
        return getDataTable(list);
    }

    /**
     * 导出车位信息列表
     */
    @RequiresPermissions("property:carport:export")
    @Log(title = "车位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CarportInfo carportInfo)
    {
        List<CarportInfo> list = carportInfoService.selectCarportInfoList(carportInfo);
        ExcelUtil<CarportInfo> util = new ExcelUtil<CarportInfo>(CarportInfo.class);
        return util.exportExcel(list, "车位信息数据");
    }

    /**
     * 新增车位信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("courtList", courtInfoService.selectCourtInfoList(new CourtInfo()));
        return prefix + "/add";
    }

    /**
     * 新增保存车位信息
     */
    @RequiresPermissions("property:carport:add")
    @Log(title = "车位信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CarportInfo carportInfo)
    {
        return toAjax(carportInfoService.insertCarportInfo(carportInfo));
    }

    /**
     * 修改车位信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        CarportInfo carportInfo = carportInfoService.selectCarportInfoById(id);
        mmap.put("carportInfo", carportInfo);
        mmap.put("courtList", courtInfoService.selectCourtInfoList(new CourtInfo()));
        return prefix + "/edit";
    }

    /**
     * 修改保存车位信息
     */
    @RequiresPermissions("property:carport:edit")
    @Log(title = "车位信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CarportInfo carportInfo)
    {
        return toAjax(carportInfoService.updateCarportInfo(carportInfo));
    }

    /**
     * 删除车位信息
     */
    @RequiresPermissions("property:carport:remove")
    @Log(title = "车位信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(carportInfoService.deleteCarportInfoByIds(ids));
    }
}
